﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JihankiLib;

namespace GuiJihanki
{
    partial class JihankiItemBoxUnitControl : UserControl
    {
        public JihankiItemBoxUnitControl()
        {
            InitializeComponent();
        }

        private JihankiItemUnitBoxProcesser iBox;

        public void Initialize(JihankiItemUnitBoxProcesser iBox)
        {
            this.iBox = iBox;
            lblValue.Text = string.Format("金額:{0:00}円", iBox.ItemValue);
            iBox.MoneyStatusChanged_ReadyToBuy +=new EventHandler(iBox_MoneyStatusChanged_ReadyToBuy);
            iBox.RejectedMoney +=new EventHandler(iBox_RejectedMoney);
            UpdateStockCount();
            btnPush.Enabled = false;
        }

        void iBox_RejectedMoney(object sender, EventArgs e)
        {
            btnPush.Enabled = false;
        }

        void iBox_MoneyStatusChanged_ReadyToBuy(object sender, EventArgs e)
        {
            UpdateStockCount();
            UpdatePushButtonEnabled();
        }

        private void UpdateStockCount()
        {
            lblStock.Text = String.Format("{0:00}個", iBox.Count);
        }

        private void UpdatePushButtonEnabled()
        {
            btnPush.Enabled = iBox.ExistStock();
        }

        private void btnPush_Click(object sender, EventArgs e)
        {
            iBox.PurchaseItem();
            UpdateStockCount();
        }
    }
}
